﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MapLibrary.Players.CollisionResponse
{
    class DamageOverTimeBehavior : CollisionBehavior
    {

        private IDamageable toDamage;
        private int damageAmount;
        private int framesPerTick;

        private int counter;

        public DamageOverTimeBehavior(IDamageable toDamage, int damageAmount, int framesPerTick)
        {
            this.damageAmount = damageAmount;
            this.toDamage = toDamage;
            this.framesPerTick = framesPerTick;
            this.counter = 0;
        }

        public override void Update(bool contained)
        {
            if (contained)
            {
                this.counter++;

                if (counter >= framesPerTick)
                {
                    counter = 0;
                    toDamage.DealDamage(damageAmount);
                }
            }
            else
                this.counter = 0;
        }
    }
}
